package com.anjubao.parking.municipal.roadside.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.roadside.common.Constants;
import com.anjubao.parking.municipal.roadside.form.CapturePicForm;
import com.anjubao.parking.municipal.roadside.form.InParkingRecordForm;
import com.anjubao.parking.municipal.roadside.form.OutParkingRecordForm;
import com.anjubao.parking.municipal.roadside.service.ParkingImageService;
import com.anjubao.parking.municipal.roadside.service.ParkingRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sync/vehicle")
public class ParkingRecordController {

    private static final Logger logger = LoggerFactory.getLogger(ParkingRecordController.class);

    @Autowired
    private ParkingRecordService recordService;
    @Autowired
    private ParkingImageService detailService;

    /**
     * 车辆进场
     * @param inForm
     * @return
     */
    @PostMapping("/in")
    public ApiResult<String> inParkRecord(@RequestBody @Validated InParkingRecordForm inForm) {
        logger.info("【车辆进场】===>车场编号:{},车位编号:{},进场时间：{}",
                inForm.getParkingLotCode(),inForm.getSlotNum(),inForm.getInTime());
        return ApiResult.success(recordService.inParkRecord(inForm));
    }

    /**
     * 车辆抓拍图片
     * @param picForm
     * @return
     */
    @PostMapping("/pic")
    public ApiResult inPic(@RequestBody @Validated CapturePicForm picForm){
        logger.info("【车辆抓拍图片】===>停车id:{},抓拍时间:{},图片类型:{}",
                picForm.getParkingRecordId(),picForm.getCaptureTime(),picForm.getType());
        detailService.save(picForm);
        return ApiResult.success();
    }

    /**
     * 车辆出场
     * @param outForm
     * @return
     */

    @PostMapping("/out")
    public ApiResult outParkRecord(@RequestBody @Validated OutParkingRecordForm outForm){
        logger.info("【车辆出场】===>停车id:{},出场时间:{} ",outForm.getParkingRecordId(),outForm.getOutTime());
        recordService.outParkRecord(outForm.getOutTime(),outForm.getParkingRecordId(), Constants.car_out_normal);
        return ApiResult.success();
    }

}